package com.yang.controller;

import com.yang.entity.UserNoteInfo;
import com.yang.service.UserNoteInfoService;
import com.yang.utils.info.NoteResponseInfo;
import com.yang.entity.ProfileThings;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户短信表(UserNoteInfo)表控制层
 *
 * @author yangdacheng
 * @since 2022-03-02 19:11:03
 */
@RestController
@RequestMapping("userNoteInfo")
@Slf4j
public class UserNoteInfoController {
    /**
     * 服务对象
     */
    @Resource
    private UserNoteInfoService userNoteInfoService;

    /**
     * 获取剩余的短信数量
     * @param uid
     * @return
     */
    @GetMapping("getTelResidue/{uid}")
    private NoteResponseInfo getTelResidue(@PathVariable("uid") String uid){
        log.info("uid==>"+uid);
        String profileTitle = "短信剩余数量";
        String background = "#84FFFF";
        NoteResponseInfo noteResponseInfo = new NoteResponseInfo();
        UserNoteInfo userNoteInfo = userNoteInfoService.queryUserNoteByUid(uid);
        ProfileThings profileThings = new ProfileThings();
        if (userNoteInfo!=null){
            profileThings.setProfileTitle(profileTitle)
                    .setProfileNumber(userNoteInfo.getNoteResidue()).setBackground(background);
        }else{
            profileThings.setProfileTitle(profileTitle).setProfileNumber(0).setBackground(background);
        }
        noteResponseInfo.setNoteCode(200).setNoteMessage("请求成功").setNoteClass(profileThings);
        return noteResponseInfo;
    }
}